package hello.mapper;

import hello.BaseMapper;
import hello.aop.AuditData;
import hello.aop.AuditOperateType;
import hello.model.Staff;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by caixx on 2016/3/21.
 */
public interface StaffMapper extends BaseMapper {

    @Select("select * from staff  ")
    @Results({
                    @Result(column = "id"),
                    @Result(column = "staff_name")
            })
    public List<Staff> getStaffs();



    @Insert({"insert  staff( staff_code, staff_name, company_id, department_id, job_state, valid_date_start, valid_date_end, post_id, position_id, super_staff_id, is_deleted, create_time, create_by, update_time, update_by) ",
            "values (  #{staffCode}, #{staffName}, #{companyId}, #{departmentId}, #{jobState}, #{validDateStart}, ",
            "#{validDateEnd}, #{postId}, #{positionId}, #{superStaffId}, #{isDeleted}, #{createTime}, #{createBy}, #{updateTime}, #{updateBy} ) "
    })
    @SelectKey(before = false, keyProperty = "id", resultType = Long.class, statement = "SELECT LAST_INSERT_ID() AS id")
    public void addStaff(Staff staff);


    @Select("select * from staff  where id = #{id} ")
    public Staff getById(@Param("id") long id);


    @Update({
            "update staff ",
            "set department_id = #{departmentId} ",
            ",  staff_name = #{staffName} ",
            "where id = #{id} ",
    })
    @AuditData(table = "staff", field = {"department_id","staff_name"}, operate = AuditOperateType.UPDATE)
    public void updateDeptId(Staff staff);


    @Delete({
            " delete from staff ",
            " where id = #{id} ",
    })
    @AuditData(table = "staff", field = {""},operate = AuditOperateType.DELETE)
    public void deleteById(Staff staff);


}
